<template>
  <div class="editor">
    <input v-model="note.title" placeholder="标题" />
    <textarea v-model="note.content" placeholder="输入内容..."></textarea>
    <button @click="saveNote">保存</button>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useRoute } from "vue-router";
import { ipc } from '@/utils/ipcRenderer';
import {ipcApiRoute} from "@/api";

const { ipcRenderer } = window.require("electron");
const route = useRoute();
const note = ref({ title: "", content: "" });
const notes = ref([]);

onMounted(async () => {
  // notes.value = await ipcRenderer.invoke("get-notes");
  // note.value = { ...notes.value[route.params.id] };
});

const saveNote = async () => {
  // notes.value[route.params.id] = note.value;
  console.log(JSON.stringify(note.value));
  // ipc.invoke(ipcApiRoute.windows.saveNotes, JSON.stringify(note.value));
  ipc.invoke(ipcApiRoute.windows.saveNotes, {title: note.value.title, content: note.value.content});
  // await ipcRenderer.invoke("save-notes", JSON.stringify(note.value));
  window.close(); // 关闭窗口
};
</script>

<style scoped>
.editor {
  display: flex;
  flex-direction: column;
  padding: 20px;
}
input,
textarea {
  margin-bottom: 10px;
}
</style>
